///PHILOTES Source Code.  (C)2012 PhiloLabs

#pragma once

#include "core/config.h"
#include "core/types.h"
#include "timing/time.h"
//#include "util/string.h"
//#include "memory/MemoryAllocObject.h"
#include <Windows.h>
#include <time.h>

//------------------------------------------------------------------------------
namespace Timing
{
class Timer
{
public:
	/// constructor
	Timer();
	/// start/continue the timer
	void Start();
	/// stop the timer
	void Stop();
	/// reset the timer
	void Reset();
	/// return true if currently running
	bool Running() const;
	/// get current time in seconds
	Timing::Time GetTime() const;
	/// get current time in ticks
	Timing::Tick GetTicks() const;

private:
	/// return internal time as 64 bit integer
	__int64 InternalTime() const;

	bool running;
	__int64 diffTime;  // accumulated time when the timer was not running
	__int64 stopTime;  // when was the timer last stopped?
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

class _PhiloCommonExport PhiloTimer : public MemAlloc_General
{
private:
	clock_t mZeroClock;

	DWORD mStartTick;
	LONGLONG mLastTime;
	LARGE_INTEGER mStartTime;
	LARGE_INTEGER mFrequency;

	DWORD_PTR mTimerMask;

public:

	PhiloTimer();
	~PhiloTimer();

	bool setOption( const Util::String& strKey, const void* pValue );

	void reset();

	unsigned long getMilliseconds();

	unsigned long getMicroseconds();

	unsigned long getMillisecondsCPU();

	unsigned long getMicrosecondsCPU();
};

}

